package components
{
	import camo.core.enum.CSSProperties;  
  
    import flash.text.StyleSheet;  
    import flash.text.TextField;  
    import flash.text.TextFormat;
    
	public class Label extends AbstractComponent
	{
        protected var _styleSheet : StyleSheet;  
		protected var textField : TextField = new TextField( );  
        protected var proxyTextFormat : TextFormat = new TextFormat( );  
        protected var _textAlign : String = CSSProperties.LEFT;  
  
        public function set autoSize(value : String) : void  
        {  
            textField.autoSize = validateAutoSize( value );  
            invalidate( );  
        }  
  
        public function set antiAliasType(value : String) : void  
        {  
            textField.antiAliasType = validateAntiAliasType( value );  
            invalidate( );  
        }
  
        public function set embedFonts(value : Boolean) : void  
        {  
            textField.embedFonts = value;
            invalidate( );  
        }  

        public function set sharpness(value : Number) : void  
        {  
            textField.sharpness = value;  
            invalidate( );  
        } 
  
        public function get text() : String  
        {  
            return textField.text;  
        }
  
        public function set text(value : String) : void  
        {  
            textField.text = value;  
            invalidate( );  
        }  

        public function set textAlign(value : String) : void  
        {  
            _textAlign = value;  
            invalidate( );  
        }
  
        public function set textFieldWidth(value : Number) : void  
        {  
            textField.width = value;  
            invalidate( );  
        }  
  
        public function set textFieldHeight(value : Number) : void  
        {  
            textField.height = value;  
            invalidate( );  
        }  
  
        public function set textFieldAlign(value : String) : void  
        {  
            proxyTextFormat.align = value;  
            invalidate( );  
        }  
        
        public function set fontFace(value : String) : void  
        {  
            font = value;  
            invalidate( );
        }
  
        public function set fontSize(value : Number) : void  
        {  
            size = value;  
            invalidate( );  
        }
  
        public function set font(value : String) : void  
        {  
            proxyTextFormat.font = value;
            invalidate( );  
        }

        public function set fontWeight(value : String) : void  
        {  
            if (value == "bold" || value == "Bold"){proxyTextFormat.bold = true}
            invalidate( );
        }
        
        public function set fontStyle(value : String) : void  
        {  
            if (value == "italic" || value == "Italic"){proxyTextFormat.italic = true}
            invalidate( );
        }

        public function set color(value : uint) : void  
        {  
            proxyTextFormat.color = value;  
            invalidate( );  
        }
  
        public function set size(value : Number) : void  
        {  
            proxyTextFormat.size = value;  
            invalidate( );  
        }  
  
        public function set letterSpacing(value : Number) : void  
        {  
            proxyTextFormat.letterSpacing = value;  
            invalidate( );  
        }
  
        public function Label( id : String = "label" )  
        {  
            super( this, id );  
        }  
  
        override protected function init() : void  
        {  
            textField.selectable = false;  
            textField.autoSize = "left";  
            addChild( textField );  
            super.init( );  
        }  
  
        override protected function draw() : void  
        {  
            proxyTextFormat.align = _textAlign;  
            
            textField.defaultTextFormat = proxyTextFormat;
            textField.setTextFormat( proxyTextFormat );  
            super.draw( );  
        }  
        
        public function setTextFormat(format : TextFormat, beginIndex : int = - 1, endIndex : int = - 1) : void  
        {  
            textField.setTextFormat( format, beginIndex, endIndex );  
        }   
  
        public static function validateAntiAliasType(value : String) : String  
        {  
            switch (value)  
            {  
                case CSSProperties.ADVANCED:  
                    return value;  
                    break;  
                default:  
                    return CSSProperties.NORMAL;  
                    break;  
            }  
        }  
  
        public static function validateAutoSize(value : String) : String  
        {  
            switch (value)  
            {  
                case CSSProperties.LEFT:  
                case CSSProperties.RIGHT:  
                case CSSProperties.CENTER:  
                    return value;  
                    break;  
                default:  
                    return CSSProperties.NONE;  
                    break;  
            }  
        }
		public function get embedFonts() : Boolean {  
			return textField.embedFonts;
 		}
		public function get font() : String  {  
			return proxyTextFormat.font; 
		}
		public function get size() : Number {  
			return Number(proxyTextFormat.size);
		}
		public function get color() : uint {  
			return uint(proxyTextFormat.color);
		}
		public function get bold() : Boolean {  
			return proxyTextFormat.bold;
		}
		public function get italic() : Boolean {  
			return proxyTextFormat.italic;
		}
    }  
}